var a = "https://files.ishare20.net/gifmaker", t = getApp();

Page({
    data: {
        id: 0,
        gifInfo: [],
        gifUrl: "",
        inputv: "",
        ad: {}
    },
    onLoad: function(a) {
        this.setData({
            ad: t.globalData.ad
        }), this.setData({
            gifInfo: JSON.parse(a.data)
        }), console.log(this.data.gifInfo);
    },
    getGifInfo: function(t) {
        var i = this;
        wx.request({
            url: a + "/getGifList.php?id=" + t,
            success: function(a) {
                console.log(a.data), i.setData({
                    gifInfo: a.data
                });
            }
        });
    },
    makeGif: function(i) {
        var e = this, o = i.detail.value;
        console.log(i);
        var n = e.data.gifInfo.example;
        for (var s in o) "" == o[s] && (o[s] = n[s]);
        var f = JSON.stringify(o);
        console.log(e.data.gifInfo.dir), console.log(f), wx.showLoading({
            title: "检测文本",
            mask: !0
        }), wx.request({
            url: t.globalData.apiUrl + "/checkText",
            data: {
                text: f
            },
            success: function(t) {
                wx.hideLoading(), t.data.success ? (wx.showToast({
                    title: "检查通过"
                }), wx.showLoading({
                    title: "生成中",
                    mask: !0
                }), wx.request({
                    url: a + "/api.php",
                    method: "POST",
                    data: {
                        type: e.data.gifInfo.dir,
                        data: f,
                        small: !0
                    },
                    header: {
                        "content-type": "application/x-www-form-urlencoded"
                    },
                    success: function(t) {
                        wx.hideLoading(), e.setData({
                            gifUrl: a.data
                        }), wx.navigateTo({
                            url: "./showGif?gifUrl=" + a + t.data.path
                        });
                    }
                })) : wx.showToast({
                    title: t.data.msg,
                    icon: "none"
                });
            },
            fail: function(a) {
                wx.hideLoading(), wx.showToast({
                    title: "连接出错",
                    icon: "none"
                });
            }
        });
    },
    onShareAppMessage: function(a) {
        return {
            title: "GIF表情包制作",
            path: "/pages/gifmaker/editGif?data=" + JSON.stringify(this.data.gifInfo)
        };
    },
    clearText: function(a) {
        console.log(a), this.setData({
            inputv: ""
        });
    }
});